import { ElLoading } from 'element-plus'

/* 全局请求 loading */

const loadingOptions = {
  fullscreen: true,
  lock: true,
  text: 'Loading',
  background: 'var(--el-mask-color-extra-light)'
}

let loadingInstance

export const useLoading = () => {
  /**
   * 显示全屏加载
   */
  const open = () => {
    loadingInstance = ElLoading.service(loadingOptions)
  }

  /**
   * 隐藏全屏加载
   */
  const close = () => {
    loadingInstance.close()
  }

  return {
    open,
    close
  }
}
